package com.second.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.second.common.pojo.R;
import com.second.lease.dao.CarDao;
import com.second.lease.pojo.entity.Car;
import com.second.lease.pojo.vo.AppCarDateVO;
import com.second.lease.pojo.vo.AppQueryCarVO;
import com.second.lease.pojo.vo.CarDateVO;
import com.second.lease.pojo.vo.QueryCarDate;
import com.second.lease.service.CarService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CarServiceImpl implements CarService {

    @Resource
    private CarDao carDao;
    @Override
    public R selectCar(QueryCarDate queryCarDate) {
        PageHelper.startPage(queryCarDate.getPageno(),queryCarDate.getPagesize());
        List<CarDateVO> list = carDao.selectCar(queryCarDate);
        PageInfo pageInfo = new PageInfo(list);
        return R.success().putListData(list).putObject(pageInfo);
    }

    @Override
    public R updateCar(Car car) {
        int i = carDao.updateById(car);
        if (i >0) {
            return R.success();
        }
        return R.error();
    }

    @Override
    public R insertCar(Car car) {
        int i = carDao.insert(car);
        if (i > 0) {
            return R.success();
        }
        return R.error();
    }

    @Override
    public R deleteCar(Integer id) {
        int i = carDao.deleteById(id);
        if (i > 0) {
            return R.success();
        }
        return R.error();
    }

    @Override
    public R showCar(AppQueryCarVO appQueryCarVO) {

        List<AppCarDateVO> carList = carDao.showCar(appQueryCarVO);
        if ( carList.size() > 0) {
            return R.success().putListData(carList);
        }
        return R.error();
    }
}
